var multiparty = require('multiparty');
var http = require('http');
var fs = require('fs');

http.createServer(function(req, res) {
  if (req.url === '/upload' && req.method === 'POST') {
    // parse a file upload
    var form = new multiparty.Form({
        uploadDir:"./tmp"//必须是已创建的文件夹
    });

    form.parse(req,function(err,fields,file){
        console.log(err)
        console.log(fields)
        console.log(file)
    })
    return;
  }

  // show a file upload form
  res.end(
    fs.readFileSync("./index.html")
  );
}).listen(8080);